cmake_minimum_required(VERSION 3.12)
project(zlib_example)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 设置CMP0074策略以使用<PackageName>_ROOT变量
if(POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()

# 定义ZLIB_ROOT变量，允许用户在CMake配置时传入路径
set(ZLIB_ROOT "" CACHE PATH "Path to Zlib")

# 手动设置包含目录
include_directories(${ZLIB_ROOT}/include)

# 添加可执行文件
add_executable(zlib_example zlib_example.c)

# 为不同的配置设置链接库
target_link_libraries(zlib_example
    debug ${ZLIB_ROOT}/lib/zlibd.lib
    optimized ${ZLIB_ROOT}/lib/zlib.lib
)

# 设置Visual Studio调试环境变量，只添加Zlib路径
set_target_properties(zlib_example PROPERTIES
    VS_DEBUGGER_ENVIRONMENT "PATH=${ZLIB_ROOT}/bin")

# 设置example为启动项目
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT zlib_example)
